package com.redxun.core.api.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.redxun.core.api.config.ICoreDataSourceService;
import com.redxun.core.boot.util.FileUtil;
import com.redxun.core.common.constant.MBoolean;
import com.redxun.core.common.utils.SpringUtil;
import com.redxun.core.db.datasource.DataSourceConstant;
import com.redxun.core.db.listener.DataSourceUpdEvent;
import com.redxun.core.db.util.CommonDao;
import com.redxun.core.db.util.DataSourceUtil;
import com.redxun.core.tool.StringUtils;
import com.redxun.form.core.entity.FormDataSourceDef;
import com.redxun.form.core.service.FormDataSourceDefServiceImpl;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

/**
 * 数据源管理.
 * @author aj
 */
@Slf4j
@Component
public class BootCoreApiDataSourceImpl implements ICoreDataSourceService {

    @Autowired
    private FormDataSourceDefServiceImpl formDataSourceDefService;
    
    @Override
    public void publishConfig(String alias, JSONObject content, String target) {
        FormDataSourceDef formDataSourceDef = formDataSourceDefService.getByAlias(alias);
        if (!MBoolean.TRUE_LOWER.val.equals(formDataSourceDef.getEnable())) {
            return;
        }
        DataSourceUpdEvent updEvent = new DataSourceUpdEvent(alias);
        SpringUtil.publishEvent(updEvent);
    }

    @Deprecated
    @Override
    public void publishConfig(JSONObject content, String target) {
    
    }
    
    @Override
    public String getConfig(String source) {
        return formDataSourceDefService.getEnableJsonList().toJSONString();
    }
    
}
